import static java.lang.Math.pow;

class Solution {
    public static boolean isHappy(int n) {
        int num = n;
        while (true) {
            int sum = 0;
            while (n > 0) {
                sum = (int) (sum + pow(n % 10, 2));
                n = n / 10;
            }
            n = sum;
            if (sum == 1) return true;
            if (sum == 4) return false;
        }
    }

    public static void main1(String[] args) {
        System.out.println(isHappy(5));

    }

    public static boolean isUgly(int n) {
        if (n < 1) return false;
        while (true) {
            if (n % 2 == 0) n /= 2;
            else if (n % 3 == 0) n /= 3;
            else if (n % 5 == 0) n /= 5;
            else break;
        }
        return n == 1;
    }

    public static void main(String[] args) {
        System.out.println(isUgly(-2147483648));
    }
}